//index.js
//获取应用实例
const app = getApp();
const valid = require("../../utils/valid.js");
var posting = false;
Page({
  data: {
    hidden:true,
    tipmsg:"",
    tipno:0,
    mobile:"",
    pswold:"",
    pswnew:"",
    pswnewconfirm:"",
    disable:false,
    countdown:60,
    btnmsg:"发送短信"
  },
  input: function (e) {
    var value = e.detail.value + "";
    var key = e.currentTarget.id + "";
    this.setData({
      [key]: value,
    });
  },
  showtip(lv, msg) {
    this.setData({
      tipno: lv,
      tipmsg: msg
    })
  },
  getcode(){
    var that = this;
    if (posting) return;
    posting = true;
    console.log("posting" + posting);
    valid.get_code(
      that.data.mobile,
      {
        success(res){
          that.setData({
            disable: true
          });
          that.cd();
        },fail(code,msg){
          that.showtip(code,msg);
        }, complete(){
        }
    })
    setTimeout(function () {
      posting = false;
    }, 1000);
  },
  cd(){
    var msg;
    var time = this.data.countdown
    if (time<=0){
      msg = "重新发送";
    }else{
      msg = this.data.countdown+"s";
    }
    this.setData({
      btnmsg:msg
    });
    if (time<=0){
      setTimeout(function(){
        this.setData({
          disable: false
        });
      },1000);
    }
  },
  reset(){
    if(posting)return;
    posting  =true;
    setTimeout(function(){
      posting = false;
    },1000);
    var that = this;
    valid.reset(this.data.mobile, this.data.pswold, this.data.pswnew, this.data.pswnewconfirm,{
      success(){
          that.showtip(3,"修改成功");
          setTimeout(function () {
            wx.navigateBack({})
          }, 500);
      },fail(code,msg){
        that.showtip(code, msg);
      }
    });
  },
  Confirm:function(){
    this.setData({
      hidden:true
    })
  },
  onLoad: function () {
    
  }
})
